import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import header from '@/components/header'
import recommend from '@/components/recommend'
import video from '@/components/video'
import Count from '@/components/Count'
import space from '@/components/space'
import login from '@/components/login'
Vue.use(Router)


const router= new Router({
  routes: [
    {
      path: '/recommend',
      name: 'recommend',
      component: recommend,
  	 	//redirect:'/'
    },
    
    {
      path: '/video',
      component: video
    },
    {
      path: '/Count',
      component: Count
    },
    {
      path: '/space',
      component: space,
   		meta: { requiresAuth: true }	
    },
    {
      path: '/login',
      component: login	
    },
  ]
})

router.beforeEach((to,from,next)=>{
	if (to.matched.some(record => record.meta.requiresAuth)){
	 	if(localStorage.getItem("islogin")){
	 		next()
	 	}else{
	 		next({
	 			path: '/login',
        query: { redirect: to.fullPath }
	 		})
	 	}
	}
	else{
		next()
	}
})
export default router